home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / GPR.TRM < prev    next >
Text File  |  1992-03-25  |  12KB  |  383 lines

  1. /*
  2.  * $Id: gpr.trm,v 3.26 92/03/24 22:35:00 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - gpr.trm */
  6. /*
  7.  * Copyright (C) 1990, 1991, 1992   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   APOLLO's GPR windowing system
  25.  *
  26.  * AUTHORS
  27.  *  Michael Aramini
  28.  *  Roque D Oliveira , oliveria@caen.engin.umich.edu
  29.  * 
  30.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  31.  * 
  32.  */
  33. #include <apollo/base.h>
  34. #include <apollo/error.h>
  35. #include <apollo/gpr.h>
  36. #include <apollo/pad.h>
  37. /* landscape window */
  38. /*
  39. #define GPR_XMAX 720
  40. #define GPR_YMAX 450
  41. */
  42. /* portrait window */
  43. #define GPR_XMAX 585
  44. #define GPR_YMAX 735
  45.  
  46. #define GPR_XLAST (GPR_XMAX - 1)
  47. #define GPR_YLAST (GPR_YMAX - 1)
  48.  
  49. #define GPR_VCHAR 19
  50. #define GPR_HCHAR 10
  51. #define GPR_VTIC (GPR_YMAX/80)
  52. #define GPR_HTIC (GPR_XMAX/80)
  53.  
  54. gpr_$direction_t  gpr_path=gpr_$right;
  55. int               gpr_ang=0;            /* text angle, 0=horizontal, 1=vertical */
  56. enum JUSTIFY      gpr_justify=LEFT;     /* text is flush left */
  57.  
  58. static status_$t  status;
  59. unsigned int      DEBUG    = 0;         /* set it to 1 when debugging program */
  60.  
  61.  
  62. static void check(messagex)
  63. char *messagex;
  64. {
  65.   if (status.all = status_$ok)
  66.   {
  67.     error_$print(status);
  68.     printf("Error occurred while %s.\n", messagex);
  69.   }
  70. }
  71.  
  72. /* return whether stdout is a DM pad . Called by term.c */
  73. gpr_isa_pad()
  74. {
  75.     pad_$isa(1, &status);
  76.     return (status.all == status_$ok);
  77. }
  78.  
  79.  
  80. GPR_init()
  81. {
  82.   gpr_$offset_t dm_bitmap_size;
  83.   gpr_$bitmap_desc_t dm_bitmap_desc;
  84.   pad_$window_desc_t window;
  85.   short font_id;
  86.   stream_$id_t stream_id;
  87.   static gpr_$rgb_plane_t  hi_plane;
  88.   static gpr_$disp_char_t  display_characteristics;
  89.   static float             screen_size_r_width,screen_size_r_height ;
  90.   static short int         disp_len = sizeof(gpr_$disp_char_t);
  91.   static short int         disp_len_returned;
  92.  
  93.  
  94.   /* open a pad to do graphics in */
  95.   window.top    = 0;
  96.   window.left   = 0;
  97.   window.width  = GPR_XMAX + 10; /* 10 accounts for width of window border */
  98.   window.height = GPR_YMAX + 35; /* 35 accounts for height of window border */
  99.   pad_$create_window("",(short)0,pad_$transcript,(short)1,window,&stream_id,&status);
  100.   check("pad_$create_window");
  101.  
  102. /*  pad_$set_full_window(stream_id,(short) 1,&window, &status); */
  103. /*  pad_$set_border (stream_id,(short) 1, true, &status); */
  104.   pad_$set_scale (stream_id,(short) 1,(short) 1, &status);
  105.   pad_$set_auto_close(stream_id, (short) 1, true, &status );
  106.  
  107.   gpr_$inq_disp_characteristics(gpr_$direct,stream_id,disp_len,&display_characteristics,&disp_len_returned,&status);
  108.   check("in gpr_$inq_display_characteristics");
  109.   screen_size_r_width    = (float) display_characteristics.x_window_size;    /*x_window_size in pixels */
  110.   screen_size_r_height   = (float) display_characteristics.y_window_size;    /*y_window_size in pixels */
  111.   hi_plane  = display_characteristics.n_planes - 1;  
  112.   if(DEBUG) printf("width=%f height=%f \n",screen_size_r_width,screen_size_r_height);
  113.  
  114.   dm_bitmap_size.x_size = 1280;
  115.   dm_bitmap_size.y_size = 1024;
  116.   gpr_$init(gpr_$direct,stream_id,dm_bitmap_size,hi_plane,&dm_bitmap_desc,&status); 
  117.   check("in gpr_$init");
  118. /*
  119.   gpr_$set_obscured_opt(gpr_$pop_if_obs, &status); 
  120.   check("in gpr_$set_obscured_opt");
  121. */
  122.   gpr_$set_auto_refresh(true, &status); 
  123.   check("in gpr_$set_auto_refresh");
  124.  
  125.   /* load a font and make it current */
  126.   gpr_$load_font_file("f7x13", 5, &font_id, &status);
  127.   check("in gpr_$load_font_file");
  128.   gpr_$set_text_font(font_id, &status);
  129.   check("in gpr_$set_text_font");
  130.  
  131.   /* set up color values */
  132.   gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  133.   check("in gpr_set_draw_value");
  134.   gpr_$set_text_background_value((gpr_$pixel_value_t)(-1), &status); /* trans */
  135.   check("in gpr_$set_text_background_value");
  136.   gpr_$set_text_value((gpr_$pixel_value_t)7, &status);  /* white */
  137.   check("in gpr_$set_text_value");
  138. }
  139.  
  140.  
  141. GPR_graphics()
  142. {
  143.   gpr_$coordinate_t locx,locy,marker_size;
  144.  
  145.   (void) gpr_$acquire_display(&status);
  146.   check("in gpr_$acquire display");
  147.   gpr_$clear((gpr_$pixel_value_t)0, &status);  /* black */
  148.   check("in gpr_$clear");
  149.  
  150.   if(DEBUG) 
  151.    {
  152.     marker_size = (short) 10;  
  153.  
  154.     locx = (short) 5;
  155.     locy = (short) 5;
  156.     gpr_$set_draw_value((gpr_$pixel_value_t)2, &status);  /* white */
  157.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  158.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  159.     gpr_$move( locx, (locy + marker_size/2),&status);
  160.     gpr_$line( locx, (locy - marker_size/2),&status);
  161.     
  162.     locx = (short) (GPR_XMAX -1 - 5);
  163.     locy = (short) 5;
  164.     gpr_$set_draw_value((gpr_$pixel_value_t)3, &status);  /* white */
  165.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  166.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  167.     gpr_$move( locx, (locy + marker_size/2),&status);
  168.     gpr_$line( locx, (locy - marker_size/2),&status);
  169.     
  170.     locx = (short) 5;
  171.     locy = (short) (GPR_YMAX -1 - 5);
  172.     gpr_$set_draw_value((gpr_$pixel_value_t)4, &status);  /* white */
  173.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  174.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  175.     gpr_$move( locx, (locy + marker_size/2),&status);
  176.     gpr_$line( locx, (locy - marker_size/2),&status);
  177.     
  178.     locx = (short) (GPR_XMAX -1 - 5);
  179.     locy = (short) (GPR_YMAX -1 - 5);
  180.     gpr_$set_draw_value((gpr_$pixel_value_t)5, &status);  /* white */
  181.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  182.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  183.     gpr_$move( locx, (locy + marker_size/2),&status);
  184.     gpr_$line( locx, (locy - marker_size/2),&status);
  185.     
  186.     gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  187.     check("in gpr_$set_draw_value");
  188.    } /* end if(DEBUG) */
  189.  
  190. }
  191.  
  192.  
  193. GPR_text()
  194. {
  195.   gpr_$release_display(&status);
  196.   check("gpr_$release_display");
  197. }
  198.  
  199.  
  200. GPRold_linetype(linetype)
  201. int linetype;
  202. {
  203.   static gpr_$line_pattern_t patterns[2+5] = {
  204.       { 0xFFFF },   /* solid              1111111111111111 */
  205.       { 0x3FFF },   /* very long dashed   0011111111111111 */
  206.       { 0xFFFF },   /* solid              1111111111111111 */
  207.       { 0x5555 },   /* dotted             0101010101010101 */
  208.       { 0x3333 },   /* short dashed       0011001100110011 */
  209.       { 0xB5AD },   /* dot short-dashed   1011010110101101 */
  210.       { 0x3FFF }    /* very long dashed   0011111111111111 */
  211.                                              };
  212.   if (linetype >= 5) linetype %= 5;
  213.   gpr_$set_line_pattern((short)1, patterns[linetype+2], (short)16, &status);
  214.   check("in gpr_$set_line_pattern");
  215. }
  216.  
  217. GPR_linetype(linetype)
  218. int linetype;
  219. {
  220.   static gpr_$line_pattern_t patterns[2+7] = {
  221.       { 0xFFFF },   /* solid              1111111111111111 */
  222.       { 0x1111 },   /* long-spaced dotted 0001000100010001 */
  223.       { 0xFFFF },   /* solid              1111111111111111 */
  224.       { 0x5555 },   /* dotted             0101010101010101 */
  225.       { 0x3333 },   /* short  dashed      0011001100110011 */
  226.       { 0x7777 },   /* medium dashed      0111011101110111 */
  227.       { 0x3F3F },   /* long   dashed      0011111100111111 */
  228.       { 0x0F0F },   /* long-spaced dashed 0000111100001111 */
  229.       { 0x5F5F }    /* dot dashed         0101111101011111 */
  230.                                              };
  231.   if (linetype >= 7) linetype %= 7;
  232.   gpr_$set_line_pattern((short)1, patterns[linetype+2], (short)16, &status);
  233.   check("in gpr_$set_line_pattern");
  234.  
  235. /*
  236.   gpr_$set_draw_value((gpr_$pixel_value_t)(linetype + 1), &status);
  237.   check("in gpr_$set_draw_value");
  238. */
  239. }
  240.  
  241.  
  242. GPR_move(x, y)
  243. unsigned int x, y;
  244. {
  245.   gpr_$move((short)x, (short)(GPR_YMAX -1 - y), &status);
  246.   check("in gpr_$move");
  247. }
  248.  
  249.  
  250. GPR_vector(x, y)
  251. unsigned int x, y;
  252. {
  253.   gpr_$line((short)x, (short)(GPR_YMAX -1 - y), &status);
  254.   check("in gpr_$line");
  255. }
  256.  
  257.  
  258. GPR_put_text(x,y,str)
  259. unsigned int x,y;        /* reference point of string */
  260. char str[];              /* the text */
  261. {
  262.   gpr_$coordinate_t xgpr,ygpr;
  263.   gpr_$offset_t     str_size_in_pixels;
  264.   short int         str_len;     
  265.  
  266.   gpr_$coordinate_t locx,locy,marker_size;
  267.  
  268.   if(DEBUG) 
  269.    {
  270.     locx = (short) x;
  271.     locy = (short) (GPR_YMAX -1 - y);
  272.     marker_size = (short) 20;  
  273.     gpr_$set_draw_value((gpr_$pixel_value_t)1, &status);  /* white */
  274.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  275.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  276.     gpr_$move( locx, (locy + marker_size/2),&status);
  277.     gpr_$line( locx, (locy - marker_size/2),&status);
  278.     gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  279.    }
  280.  
  281.   xgpr = (short) x;
  282.   ygpr = (short) (GPR_YMAX -1 - y); 
  283.   gpr_$set_text_path(gpr_path, &status); 
  284.   check("gpr_$set_text_path");
  285.  
  286.   str_len = (short) strlen(str);
  287.   gpr_$inq_text_extent(str,str_len,&str_size_in_pixels,&status); /* Calculate how much space (in pixels) the string requires */    
  288.   check("in gpr_$inq_text_extent");
  289.  
  290.   switch (gpr_justify) 
  291.    {
  292.     case LEFT :
  293.         {
  294.          switch (gpr_path) 
  295.           {
  296.            case gpr_$up :           /* vertical */
  297.                {
  298.                 if(DEBUG) printf("LEFT and up , str=%s\n",str);
  299.                 break;
  300.                }
  301.            case gpr_$right :        /* horizontal */
  302.                {
  303.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  304.                 if(DEBUG) printf("LEFT and right, str=%s \n",str);
  305.                 break;
  306.                }
  307.           }
  308.          break;
  309.         }
  310.  
  311.     case CENTRE :
  312.         {  
  313.          switch (gpr_path) 
  314.           {
  315.            case gpr_$up :           /* vertical */
  316.                {
  317.                 xgpr = xgpr + str_size_in_pixels.x_size/2;
  318.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  319.                 if(DEBUG) printf("CENTRE and up, str=%s \n",str);
  320.                 break;
  321.                }
  322.            case gpr_$right :        /* horizontal */
  323.                {
  324.                 xgpr = xgpr - str_size_in_pixels.x_size/2;
  325.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  326.                 if(DEBUG) printf("CENTRE and right, str=%s \n",str);
  327.                 break;
  328.                }
  329.           }
  330.          break;
  331.         }
  332.     case RIGHT :
  333.         {
  334.          switch (gpr_path) 
  335.           {
  336.            case gpr_$up :           /* vertical */
  337.                {
  338.                 ygpr = ygpr + str_size_in_pixels.y_size;
  339.                 if(DEBUG) printf("RIGHT and up, str=%s \n",str);
  340.                 break;
  341.                }
  342.            case gpr_$right :        /* horizontal */
  343.                {
  344.                 xgpr = xgpr - str_size_in_pixels.x_size;
  345.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  346.                 if(DEBUG) printf("RIGHT and right, str=%s \n",str);
  347.                 break;
  348.                }
  349.           }
  350.          break;
  351.         }
  352.    }
  353.  
  354.   gpr_$move(xgpr,ygpr,&status);
  355.   check("in gpr_$move");
  356.   gpr_$text(str, str_len, &status);
  357.   check("in gpr_$text");
  358. }
  359.  
  360. int GPR_text_angle(ang)
  361. int ang;
  362. {   
  363.     if (gpr_ang != ang)
  364.       {
  365.         gpr_ang  = ang;
  366.         gpr_path = (gpr_ang == 1 ? gpr_$up : gpr_$right);
  367.       }
  368.     return (TRUE);
  369. }
  370.  
  371. int GPR_justify_text(mode)
  372. enum JUSTIFY mode;
  373. {
  374.     gpr_justify = mode;
  375.     return (TRUE);
  376. }
  377.  
  378. GPR_reset()
  379. {
  380.   gpr_$terminate(false, &status);
  381.   check("in gpr_$terminate");
  382. }
  383.